package com.renwei.yunlong.activity.work;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.fingdo.statelayout.StateLayout;
import com.renwei.yunlong.R;
import com.renwei.yunlong.adapter.WorkSpareObjectSelectAdapter;
import com.renwei.yunlong.base.BaseActivity;
import com.renwei.yunlong.bean.WorkSpareBean;
import com.renwei.yunlong.view.SimpleOptionView;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;
import com.renwei.yunlong.utils.CommonUtils;
import com.zyf.fwms.commonlibrary.utils.StatusBarUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

public class WorkSpareObjectSelectActivity extends BaseActivity implements BaseRecyclerViewAdapter.OnItemClickLitener {

    @Bind(R.id.simpleTileView)
    SimpleOptionView simpleTileView;
    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;
    @Bind(R.id.state_layout)
    StateLayout stateLayout;
    private WorkSpareBean workSpareBean;
    private String hardwareId;
    private WorkSpareObjectSelectAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work_spare_object_select);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(this, CommonUtils.getColor(this, R.color.title_color), 0);
        workSpareBean = (WorkSpareBean) getIntent().getSerializableExtra("workSpareBean");
        hardwareId = getIntent().getStringExtra("hardwareId");
        initView();
    }

    private void initView() {
        simpleTileView.setTitle("选择对象");

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new WorkSpareObjectSelectAdapter(this,hardwareId);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickLitener(this);
        adapter.setData(workSpareBean.getRows());
    }

    @Override
    public void onItemClick(View view, int position) {
        WorkSpareBean.RowsBean bean = adapter.getItem(position);
        Intent intent = new Intent();
        intent.putExtra("objectName",bean.getAssetName());
        if ("1".equals(companyType)){
            intent.putExtra("objectId",bean.getAssetId());
        }else{
            intent.putExtra("objectId",bean.getAssetId()+"");
        }
        setResult(RESULT_OK,intent);
        finish();
    }

    public static void OpenActivity(Fragment fragment, String hardwareId, WorkSpareBean workSpareBean, int requestCode){
        Intent intent = new Intent(fragment.getContext(),WorkSpareObjectSelectActivity.class);
        intent.putExtra("workSpareBean",workSpareBean);
        intent.putExtra("hardwareId",hardwareId);
       fragment.startActivityForResult(intent,requestCode);
    }
}
